﻿<%@ Application Language="VB" %>
<%@ Import Namespace="log4net" %>
<%@ Import Namespace="log4net.Config" %>

<script runat="server">
 
    Dim logger As log4net.ILog

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs on application startup
        'log4net.Config.DOMConfigurator.Configure()
        log4net.Config.XmlConfigurator.Configure()
        Dim adapter As New LoginDSTableAdapters.LoginLogTableAdapter
        adapter.DeleteQueryAll()
    End Sub
    
    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs on application shutdown
        Dim adapter As New LoginDSTableAdapters.LoginLogTableAdapter
        adapter.DeleteQueryAll()
    End Sub
    Private Sub Application_PreRequestHandlerExecute(sender As [Object], e As EventArgs)
        If Context.Session IsNot Nothing Then
            ' your custom code
            If Session.IsNewSession Then
                
            End If
        End If
    End Sub
    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        '' Code that runs when an unhandled error occurs
        'Dim adapter As New LoginDSTableAdapters.LoginLogTableAdapter
        'adapter.DeleteQueryAll()
        
        Dim objErr As Exception = Server.GetLastError().GetBaseException()
        Dim err As String = "Error Caught in Application_Error event" & _
                            System.Environment.NewLine & _
                            "Error in: " & Request.Url.ToString() & _
                            System.Environment.NewLine & _
                            "Error Message: " & objErr.Message.ToString() & _
                            System.Environment.NewLine & _
                            "Stack Trace:" & objErr.StackTrace.ToString()
        ' Server.ClearError()
        logger = log4net.LogManager.GetLogger("Application_Error")
        logger.Error(System.Diagnostics.EventLogEntryType.Error & "-" & err)
        'Response.Redirect("ErrorPage.aspx")
    End Sub

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when a new session is started

        Session.Add("LoginUser", "")
        Session.Add("LoginFail", 0)
    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when a session ends. 
        ' Note: The Session_End event is raised only when the sessionstate mode
        ' is set to InProc in the Web.config file. If session mode is set to StateServer 
        ' or SQLServer, the event is not raised.
        Dim adapter As New LoginDSTableAdapters.LoginLogTableAdapter
        adapter.DeleteQuery(Session.SessionID)
    End Sub
       
</script>